let Mock  = require('mockjs');
let Random = Mock.Random;

//Mock 随机生成
// Random.integer(60, 100)    => 78
// Random.float(60, 100)      => 89.565475
// Random.range(60, 100)      => [60,61,62,...,99]
// Random.date()              => "2018-12-28"
// Random.image('200x100','#396') => "http://dummyimage.com/200x100/396"
// Random.color()             => "#79d8f2"  (默认使用hex颜色)
// Random.county(true)        => "浙江省 舟山市 岱山县"
// Random.cparagraph(1,3)       生成1-3个句子 ==>"电力速率离老五准东其引是外适只王。体区先手天里己车发很指一照委争本。究利天易里根干铁多而提造干下志维。级素一门件一压路低表且太马。"

const data = { 
      news: [],
      goods:[]
};

//手动写入静态数据
data.user = [
  { 
    id:1,
    username:"22222",
    age:22
  }
]

//随机生成商品信息
function randomGoods(){
  var images = [1,2,3].map(x=>Random.image('200x100', Random.color(), Random.word(2,6)));
  for (var i = 0; i < 100; i++) {
    data.goods.push({
         id: i, 
         goodName: Random.cword(8,20),
         price:Random.float(1, 100),
         createDate:Random.date(),
         desc: Random.cparagraph(1,3),
         images: images.slice(0,Random.integer(1,3))
    })
  }
}

//随机生成新闻信息
function randomNews(){
  var images = [1,2,3].map(x=>Random.image('200x100', Random.color(), Random.word(2,6)));
  for (var i = 0; i < 100; i++) {
    var content = Random.cparagraph(0,10);
    data.news.push({
         id: i, 
         title: Random.cword(8,20),
         desc: content.substr(0,40),
         tag: Random.cword(2,6),
         views: Random.integer(100,5000),
         images: images.slice(0,Random.integer(1,3))
    })
  }
}

module.exports = function() {
  randomGoods();
  randomNews();
  return data
}